package com.uml.youmath;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

/**
 * The StageSelection Activity class. This view is defined as the screen where
 * the player has chosen their subject (addition, division, etc) and now is
 * going to choose a level on the map TODO: Is the difficulty mode implied here?
 * Chosen here? Or set in the Options?
 * 
 * @author cdietsch
 * 
 */
public class StageSelection extends Activity implements OnClickListener {

	Button btn_play; // btn_back5, btn_play;
	ImageButton btn_easy, btn_normal, btn_hard, btn_expert;
	boolean continueMusic = true;
	
	int gameType = 0, stageSelect = 0, currentPos = 0;

	TextView stageSelectionText, gameTypeText;

	@Override
	public void onClick(View v) {

		if (v == btn_easy) {
			stageSelect = 0;
		}
		if (v == btn_normal) {
			stageSelect = 1;
		}
		if (v == btn_hard) {
			stageSelect = 2;
		}
		if (v == btn_expert) {
			stageSelect = 3;
		}

		// send along more parameters later, but the heart of this
		// is to go ahead and start the game now
		Intent i = new Intent(StageSelection.this, NewGame.class);
		i.putExtra("gametype", gameType);
		i.putExtra("stageselect", stageSelect);
		startActivity(i);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.stageselection);

		// get data from previous activity
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			gameType = extras.getInt("gametype");
		}

		gameTypeText = (TextView) findViewById(R.id.gameTypeText);

		switch (gameType) {
		case ProblemMaker.ADDITION:
			gameTypeText.setText(getResources().getString(R.string.addition));
			break;
		case ProblemMaker.SUBTRACTION:
			gameTypeText
					.setText(getResources().getString(R.string.subtraction));
			break;
		case ProblemMaker.MULTIPLICATION:
			gameTypeText.setText(getResources().getString(
					R.string.multiplication));
			break;
		case ProblemMaker.DIVISION:
			gameTypeText.setText(getResources().getString(R.string.division));
			break;
		case ProblemMaker.NUMBER_IDENTITY:
			gameTypeText.setText(getResources().getString(R.string.identity));
			break;
		}


		btn_easy = (ImageButton) findViewById(R.id.btn_easy);
		btn_normal = (ImageButton) findViewById(R.id.btn_normal);
		btn_hard = (ImageButton) findViewById(R.id.btn_hard);
		btn_expert = (ImageButton) findViewById(R.id.btn_expert);

		btn_easy.setOnClickListener(this);
		btn_normal.setOnClickListener(this);
		btn_hard.setOnClickListener(this);
		btn_expert.setOnClickListener(this);

	}

	@Override
	public void onPause() {
		currentPos = SoundService.musicPlayer.getCurrentPosition();
		SoundService.currentPos = currentPos;
		SoundService.musicPlayer.pause();
		super.onPause();
	}
	
	@Override
	public void onResume() {
		SoundService.resumeAt();
		super.onResume();
	}
}
